﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ComputerResourceConsole.view
{
    public partial class frm_debug_setting : Form
    {
        private string _host;
        private int _port;
        private string _instanceID;

        public string Host
        {
            get
            {
                return this._host;
            }
            set 
            {
                this._host = value;
            }
        }

        public int Port
        {
            get 
            {
                return this._port;
            }
            set
            {
                if (value < 1024 || value > 65534)
                {
                    throw new Exception("Port value should be ranged in 1024 and 65535!");
                }
                this._port = value;
            }
        }

        public string InstanceID
        {
            get
            {
                return this._instanceID;
            }
            set
            {
                this._instanceID = value;
            }
        }

        public frm_debug_setting()
        {
            this._host = "127.0.0.1";
            this._port = 6002;
            this._instanceID = "3667daec-e545-4d00-9f05-6fcff7e16c85";
            InitializeComponent();
        }

        private void btn_ok_Click(object sender, EventArgs e)
        {
            try
            {
                this.Host = this.tb_host.Text;
                this.Port = Convert.ToInt32(this.tb_port.Text);
                this.InstanceID = this.tb_insID.Text;
                this.DialogResult = System.Windows.Forms.DialogResult.OK;
                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }

        private void btn_cancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
            this.Close();
        }

        private void frm_debug_setting_Load(object sender, EventArgs e)
        {
            this.tb_host.Text = this._host;
            this.tb_port.Text = this._port.ToString();
            this.tb_insID.Text = this._instanceID;
        }
    }
}
